const express = require('express');
const app = express();
// 设置白名单
const whiteList = ["http://localhost:3000"];
app.use((request, response, next) => {
    response.setHeader('Access-Control-Allow-Origin', whiteList.join(","));
    response.setHeader('Access-Control-Allow-Methods', 'PUT,DELETE,POST,GET');
    response.setHeader('Access-Control-Allow-Headers', 'name,age');
    response.setHeader('Access-Control-Allow-Credentials', true);
    response.setHeader('Access-Control-Max-Age', 3);
    response.setHeader('Access-Control-Expose-Headers', 'Date,age,Connection');
    next();
});
app.put('/getData', (request, response) => {
    console.log("[PUT] come in...");
    response.end("put ok");
});
app.get('/getData', (request, response) => {
    console.log("[GET] come in...");
    response.setHeader("age", 25);
    response.end("ok");
});
app.listen(3001);